package com.hjw.junit;

import com.hjw.exer.Commodity;
import com.hjw.exer.CommodityOperation;

/**
 * 该类主要用来测试商品操作类对商品类的管理功能是否正常
 * 主要功能包括：crud
 * @author hjwStrart
 * @create 2022-01-07 17:39
 */
public class TestCommodity {
    public static void main(String[] args) {
        Commodity[] commodities = new Commodity[5];
//        for (int i = 0; i < commodities.length; i++) {
//            commodities[i] = new Commodity(i + 1 + "号商品",format(Math.random()*90+10),format((Math.random()*3+5)),(int)(Math.random()*900+100));
//        }
//        for (Commodity commodity : commodities) {
//            System.out.println(commodity);
//        }
        CommodityOperation commodityOperation = new CommodityOperation(commodities);
        for (int i = 0; i < 3; i++) {
           commodityOperation.addGoods( commodities[i] = new Commodity(i + 1 + "号商品",format(Math.random()*90+10),format((Math.random()*3+5)),(int)(Math.random()*900+100)));
        }
//        commodityOperation.getAllCommoditiesInfo();
//        commodityOperation.deleteGoods(4);
//        commodityOperation.deleteGoods(1);
//        commodityOperation.getAllCommoditiesInfo();
        commodityOperation.updateGoods("1号商品",new Commodity());
        commodityOperation.getAllCommoditiesInfo();

    }

    public static Double format(Double d){
        String format = String.format("%.2f", d);
        return Double.parseDouble(format);
    }
}

